package com.ruochen.recipe;

import android.app.ActivityManager;
import android.app.Application;
import android.content.Context;

import androidx.multidex.MultiDex;

import com.blankj.utilcode.util.Utils;
import com.lxj.xpopup.XPopup;

import java.util.List;

public class AppApplication extends Application {
    private static AppApplication instances;

    public static AppApplication getInstances() {
        return instances;
    }
    @Override
    public void onCreate() {
        super.onCreate();
        String processName = getProcessName(this, android.os.Process.myPid());
        if (processName != null) {
            boolean defaultProcess = getPackageName().equals(processName);
            if (defaultProcess) {
                instances = this;
                //我的：95fb6be1ed
                //测试：fa28fc478f
                //CrashReport.initCrashReport(getApplicationContext(), "95fb6be1ed", true);
                Utils.init(this);
                //
                XPopup.setAnimationDuration(300);
            }
        }
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }


    public static String getProcessName(Context cxt, int pid) {
        ActivityManager am = (ActivityManager) cxt.getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningAppProcessInfo> runningApps = am.getRunningAppProcesses();
        if (runningApps == null) {
            return null;
        }
        for (ActivityManager.RunningAppProcessInfo procInfo : runningApps) {
            if (procInfo.pid == pid) {
                return procInfo.processName;
            }
        }
        return null;
    }
}
